package com.ruoyi.message.web.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.ruoyi.common.core.plus.web.controller.BasePlusController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.message.general.entity.MessageCountry;
import com.ruoyi.message.manage.service.ManageMessageCountryService;
import com.ruoyi.message.web.model.vo.WebMessageCountryVo;
import com.ruoyi.system.api.service.ILanguageApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/message/web/messageCountry")
@Api(tags = "WEB消息国家")
public class WebMessageCountryController extends BasePlusController {

    @Autowired
    private ManageMessageCountryService manageMessageCountryService;

    private ILanguageApiService iLanguageApiService;

    /**
     * 查询消息国家列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "分页")
    public AjaxResult list() {
        List<MessageCountry> messageCountryList = manageMessageCountryService.getByList(null);
        List<WebMessageCountryVo.CommonVo> convert = Convert.convert(new TypeReference<List<WebMessageCountryVo.CommonVo>>() {
        }, messageCountryList);
        Map<String, String> coinTradeAbstracts = iLanguageApiService.getByDict("coin_trade_message_country", null, "coinTrade");
        convert.forEach(d -> {
            String name = coinTradeAbstracts.get(d.getName());
            d.setName(name == null ? d.getName() : name);
        });
        return AjaxResult.success(convert);
    }

}
